
//
//  CustomSearchTextField.m
//  MediumMottoUnion
//
//  Created by 吕友超 on 14-9-22.
//  Copyright (c) 2014年 liuchang. All rights reserved.
//

#import "CustomSearchTextField.h"

@implementation CustomSearchTextField

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self initView];
    }
    return self;
}


-(void)initView{
    
    self.keyboardType = UIKeyboardTypeDefault;
    self.tintColor = MAIN_BLACK_COLOR;
    self.background = [UIImage imageNamed:@"home_research"];
    [self.layer setCornerRadius:0];
    self.clipsToBounds = YES;
    self.clearsOnBeginEditing = YES;
    self.leftViewMode = UITextFieldViewModeAlways;
    self.returnKeyType = UIReturnKeySearch;
//    [[UITextField appearance]setBackground:[UIImage imageNamed:@"home_research"]];
//    [[UITextField appearance] setTintColor:MAIN_GRAY_COLOR];
    self.clearButtonMode = UITextFieldViewModeAlways;
    self.placeholder = @"请输入名称或社区号搜索社区";
    [self setValue:[UIFont boldSystemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];
    [self setValue:MAIN_GRAY_COLOR forKeyPath:@"_placeholderLabel.textColor"];
    self.font = [UIFont systemFontOfSize:14];
    UIImage* img1 = [UIImage imageNamed:@"search"];
    UIImageView* imgV = [[UIImageView alloc] initWithImage:img1];
    imgV.frame = CGRectMake(8, 5, img1.size.width/2, img1.size.height/2);
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, imgV.width, imgV.height)];
    [view addSubview:imgV];
    [self setLeftView:view];
    
}

- (CGRect)textRectForBounds:(CGRect)bounds{
    CGRect inset = CGRectMake(bounds.origin.x+30, bounds.origin.y+1, bounds.size.width -10, bounds.size.height);//更好理解些
    return inset;
}

-(CGRect)placeholderRectForBounds:(CGRect)bounds
{
    
    //return CGRectInset(bounds, 20, 0);
    CGRect inset = CGRectMake(bounds.origin.x+30, bounds.origin.y+1, bounds.size.width -10, bounds.size.height);//更好理解些
    return inset;
}

//控制编辑文本的位置
-(CGRect)editingRectForBounds:(CGRect)bounds
{
    //return CGRectInset( bounds, 10 , 0 );
    
    CGRect inset = CGRectMake(bounds.origin.x +30, bounds.origin.y, bounds.size.width -10, bounds.size.height);
    return inset;
    
}


//控制左视图位置
- (CGRect)leftViewRectForBounds:(CGRect)bounds
{
    CGRect inset = CGRectMake(bounds.origin.x, bounds.origin.y+8, 15, bounds.size.height);
    return inset;
    //return CGRectInset(bounds,50,0);
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect
 {
 // Drawing code
 }
 */

@end
